package com.yx.frame.builder.code;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;

import com.yx.frame.service.Action;
import com.yx.frame.authority.AuthorityManager;
import com.yx.frame.builder.validate.ServiceBuilderConfigManager;
import com.yx.frame.builder.xml.ServiceBuilderXml;
import com.yx.frame.builder.xml.MethodXml;
import com.yx.frame.jdbc.Sql;


public class ClassBuilder {

	String className = null;
	String classPackagename = null;
	String filePath = null;
	String javaClientfilePath=null;
	String rootPathStr = null;
	List<MethodBuilder> methodBuilders = new ArrayList<MethodBuilder>();

	public ClassBuilder(File rootPath, File file, ServiceBuilderXml appHelperXml,
			CodeGenerator codeGenerator) {
		if (file.getName().toLowerCase().endsWith(".rsb")) {
			className = file.getName();
			className = className.substring(0, className.length() - 4);
		}
		rootPathStr = rootPath.getPath();
		filePath = file.getParent() + "/" + className + ".java";
		
		javaClientfilePath= file.getParent() + "/" + className + "Client.java";

		classPackagename = file.getParent();
		classPackagename = classPackagename.substring(rootPath.getPath()
				.length() + 1, classPackagename.length());

		classPackagename = classPackagename.replaceAll("\\\\", ".");

		List<MethodXml> methods = appHelperXml.getMethods();
		for (int i = 0; i < methods.size(); i++) {
			MethodXml method = methods.get(i);
			MethodBuilder methodBuilder = null;
			try {
				if ("query".equals(method.getType())) {
					methodBuilder = new QueryMethodBuilder(classPackagename
							+ "." + className, className, method);
					methodBuilders.add(methodBuilder);
				} else if ("update".equals(method.getType())) {
					methodBuilder = new UpdateMethodBuilder(classPackagename
							+ "." + className, className, method);
					methodBuilders.add(methodBuilder);
				} else if ("java".equals(method.getType())) {
					methodBuilder = new JavaMethodBuilder(classPackagename
							+ "." + className, className, method);
					methodBuilders.add(methodBuilder);
				}
			} catch (Exception e) {
				e.printStackTrace();
				if (methodBuilder != null) {
					codeGenerator.addMessage("文件" + filePath + "中"
							+ method.getName() + "方法解析出错，该方法将会跳过："
							+ e.getMessage() + "\r\n");
				} else {
					codeGenerator.addMessage("文件" + filePath
							+ "中方法解析出错，该方法将会跳过：" + e.getMessage() + "\r\n");
				}
			}
		}
	}
	public static JsFileWriter createJsWebFile(String rootPath,String jsFileName,String jsControlName)throws Exception{
		File path = new File(rootPath + "/client/js/");
		if (!path.exists()) {
			path.mkdirs();
		}
		String jsFilePath = rootPath + "/client/js/"+jsFileName+".js";
		File file = new File(jsFilePath);
		if (file.exists()) {
			file.delete();
		}
		String jsAppFilePath = rootPath + "/client/js/"+jsFileName+"_app.js";
		File appFile = new File(jsAppFilePath);
		if (appFile.exists()) {
			appFile.delete();
		}
		String jsDocFilePath = rootPath + "/client/"+jsFileName+".html";
		File docFile = new File(jsDocFilePath);
		if (docFile.exists()) {
			docFile.delete();
		}
		
		OutputStreamWriter jsWriter = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
		OutputStreamWriter jsAppWriter = new OutputStreamWriter(new FileOutputStream(appFile), "UTF-8");
		OutputStreamWriter docWriter = new OutputStreamWriter(new FileOutputStream(docFile), "UTF-8");
		
		docWriter.write("<!DOCTYPE html>\r\n");
		docWriter.write("<html>\r\n");
		docWriter.write("<head>\r\n");
		docWriter.write("	<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />\r\n");
		docWriter.write("    <meta http-equiv=\"Content-Style-Type\" content=\"text/css\" />\r\n");
		docWriter.write("	<title>"+jsFileName+"开发帮助手册</title>\r\n");
		docWriter.write("</head>\r\n");
		docWriter.write("<body>\r\n");
		docWriter.write("<h1 style=\"text-align:center;\">"+jsFileName+"开发帮助手册</h1>\r\n");
		docWriter.write("<p><font color=red>1、为了降低JS文件大小和网络流量，方法命名和数据元素命名尽量不要过长。</font></p>\r\n");
		docWriter.write("<p><font color=red>2、字段名setUser、getUser、serverUrl、IsOK、Message、isOK、message为保留字段在数据元素声明中不要使用。</font></p>\r\n");
		docWriter.write("<p><font color=red>3、在同一RSB描述文件中函数不能重名，在设计中建议最好在所有文件中函数不要重名。</font></p>\r\n");
		docWriter.write("<p><font color=red>4、注意方法ID，是在所有文件中不能重复并且从0开始的连续数字，用于唯一区分不同方法。</font></p>\r\n");
		
		docWriter.flush();
		
		JsFileWriter writer=new JsFileWriter(jsWriter,jsAppWriter,docWriter);
		writer.write("true","var "+jsFileName+"=function(){\r\n");
		writer.write("true","	this.serverUrl=\""+ServiceBuilderConfigManager.getInstance().getServerUrl()+"\";this.smartframeUID = \"wukai\";this.asyncFlag = true;this.pKey=CryptoJS.enc.Utf8.parse(\""+AuthorityManager.PUBLIC_KEY+"\");\r\n");
		writer.html("true","", "setUser(iUserName,iPassword)", "设置用户名/密码，服务器端服务器端用于身份认证，没有正确的用户名/密码服务器拒绝服务,如果采用记住密码模式，系统缓存UID（通过getUID()得到并存储），调用setUID(uid)设置，只要UID在有效期内，服务器将会认证通过", "系统", "", "iUserName:String,iPassword:String", "无", jsControlName+".setUser(iUserName,iPassword);");
		writer.write("true","	this.setUID=function(uid){this.smartframeUID=uid;};this.getUID=function(){return this.smartframeUID;};\r\n");
		writer.write("true","	this.setUser=function(iUserName,iPassword){");
		writer.write("true","var timestamp = (new Date()).valueOf();");
		writer.write("true","var md5KeyStr=CryptoJS.MD5(iPassword+timestamp).toString();");
		writer.write("true","md5KeyStr=md5KeyStr.substring(0, 16);");
		writer.write("true","var md5key = CryptoJS.enc.Utf8.parse(md5KeyStr);");
		writer.write("true","var iv  = CryptoJS.enc.Utf8.parse(md5KeyStr);");
		writer.write("true","var srcs = CryptoJS.enc.Utf8.parse(timestamp);");
		writer.write("true","var encrypted = CryptoJS.AES.encrypt(srcs, md5key, { iv: iv,mode:CryptoJS.mode.CBC});");
		writer.write("true","var signTxt=JSON.stringify([iUserName,encrypted.toString(),timestamp]);");
		writer.write("true","var signSrcs=CryptoJS.enc.Utf8.parse(signTxt);");
		writer.write("true","var signEncrypted = CryptoJS.AES.encrypt(signSrcs, this.pKey, { iv: this.pKey, mode: CryptoJS.mode.CBC});");
		writer.write("true","this.smartframeUID= signEncrypted.toString();return this.smartframeUID;");   
		writer.write("true","};\r\n");
		
		writer.write("true","	this.jsonPost = function(actionId,asyncService,requestData,dataConvertFunction,callbackFunction) {");
		writer.write("true","var url = this.serverUrl + \"JsonRemote\";");
		//writer.write("true","var timestamp = (new Date()).valueOf();");
		writer.write("true","var xmlhttp;");
		writer.write("true","var data = {ActionId: actionId,UId: this.getUID(),YibuService: asyncService,RequestData: requestData};");
		writer.write("true","if (window.XMLHttpRequest) {");                
		writer.write("true","xmlhttp = new XMLHttpRequest();");
		writer.write("true","if (xmlhttp.overrideMimeType) {");
		writer.write("true","xmlhttp.overrideMimeType('text/xml');");
		writer.write("true","}");
		writer.write("true","}else if (window.ActiveXObject){");
		writer.write("true","xmlhttp = new ActiveXObject(\"Microsoft.XMLHTTP\");");
		writer.write("true","}");
		writer.write("true","xmlhttp.onreadystatechange=function(){");
		writer.write("true","if (4 == xmlhttp.readyState){");
		writer.write("true","if(200 == xmlhttp.status) {");
		writer.write("true","var rspobj = xmlhttp.responseText;");
		writer.write("true","if (rspobj) {");
		writer.write("true","dataConvertFunction(JSON.parse(rspobj), callbackFunction);");
		writer.write("true","} else {");
		writer.write("true","callbackFunction(false, \"服务器没有返回信息\");");
		writer.write("true","}");
		writer.write("true","}else{");
		writer.write("true","callbackFunction(false, \"服务器拒绝访问\");");
		writer.write("true","}");
		writer.write("true","}");
		writer.write("true","};");
		writer.write("true","xmlhttp.open(\"post\", url, this.asyncFlag);");
		writer.write("true","xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');");
		writer.write("true","xmlhttp.send(encodeURIComponent(JSON.stringify(data)));");
		writer.write("true","};\r\n");
		
		writer.write("true","	this.exportExcel = function(ActionId, Header, RequestData, Title, Processer, FileName, JsonDataFormat, HeaderMergedRegion, ColumnData) {");
		writer.write("true","var iframe = $('<iframe id=\"file_upload_return\" hidden=\"true\" name=\"file_upload_return\"></iframe>');");
		writer.write("true","$(iframe).appendTo('body');");
		writer.write("true","var url = this.serverUrl + \"Download\";");
		writer.write("true","var data = {ActionId: ActionId,UId: this.getUID(),YibuService: '',Header: encodeURI(Header),RequestData: encodeURI(RequestData),Title: encodeURI(Title),Processer: Processer,FileName: encodeURI(FileName),JsonDataFormat: encodeURI(JsonDataFormat),HeaderMergedRegion: encodeURI(HeaderMergedRegion),ColumnData: encodeURI(ColumnData)};");
		writer.write("true","var form = $('<form  action=\"' + url + '\" method=\"POST\" name=\"FormExcel\" target=\"file_upload_return\" id=\"FormExcel\"></form>');");
		writer.write("true","if (data) {for (var i in data) {$('<input type=\"hidden\" name=\"' + i + '\" value=\"' + data[i] + '\" />').appendTo(form);}}");
		writer.write("true","$(form).attr('style', 'display:none');$(form).appendTo('body');$(form).submit();$(form).remove();");
		writer.write("true","$(\"#file_upload_return\").load(function() {var body = $(window.frames['file_upload_return'].document.body);if (body[0].textContent != '') {var data = eval('(' + body[0].textContent + ')');alert(data.Message);}$(iframe).remove();});");
		writer.write("true","};\r\n");
		
		
		MobileControls mobileControls=new MobileControls(jsControlName,writer);
		StringBuffer sb=new StringBuffer();
		sb.append("	"+jsControlName+".fileUploader(fileComboInput,function(isOK,message,fileUrls){<br>\r\n"); 
		sb.append("	    &nbsp;&nbsp;if(isOK){//服务调用成功,从fileUrls数组中取出服务器存储文件路径<br>\r\n");
		sb.append("	    &nbsp;&nbsp;}else{//服务调用失败，返回错误信息<br>\r\n");
		sb.append("	        &nbsp;&nbsp;&nbsp;&nbsp;var errorMessage=message;<br>\r\n");
		sb.append("	    &nbsp;&nbsp;}<br>\r\n");
		sb.append("	});\r\n");		
		writer.html("false","", "fileUploader(fileComboInput, callbackFunction)", 
				"CrossUI框架下文件上传服务，服务器端文件存储位置需要根据具体情况通过接口com.yx.frame.server.Provider实现",
				"系统", "", "file：fileComboInput：ComboInput文件选择框对象", "返回数据存储在标签FileUrls中，存储方式为数组",
				sb.toString());
		writer.write("false","	this.fileUploader=function(fileComboInput, callbackFunction) {");
		writer.write("false","var file=fileComboInput.getUploadObj();");
		writer.write("false","if(!file){");
		writer.write("false","callbackFunction(false,\"文件为空不能上传\");");
		writer.write("false","return;");
		writer.write("false","}");
		writer.write("false","var url = this.serverUrl + \"FileUpload\";");
		//writer.write("false","var timestamp = (new Date()).valueOf();");
		writer.write("false","var data = { key:'upload',UId: this.getUID(),file:file};");
		writer.write("false","xui.IAjax(url,data,function(rsp){");
		writer.write("false","if(rsp){");
		writer.write("false","callbackFunction(rsp.IsOK,rsp.Message,rsp.FileUrl);");
		writer.write("false","}else{");
		writer.write("false","callbackFunction(false,\"服务器没有返回信息\");");
		writer.write("false","}");		
		writer.write("false","},function(errMsg){");
		writer.write("false","callbackFunction(false,errMsg);");                
		writer.write("false","}).start();");
		writer.write("false","};\r\n");	
		
		writer.html("true","", "copy(jsonRows,fromKeys,toKeys)", "工具方法，用于将行存数的JSON对象的指定列复制成新列名的json对象",
				"系统", "", "jsonRows：为行存数的查询结果集;fromKeys:源列名数组；toKeys：目的列名数组", "json数组",
				"var rowsData="+jsControlName+".copy(XT_MKXX,[\"MKXX_DM\",\"MKXX_MC\",\"MKXX_IMAGE_URL\"],[\"id\",\"caption\",\"image\"]);");
		writer.write("true","	this.copy=function(jsonRows,fromKeys,toKeys){");	
		writer.write("true","if(!jsonRows||!fromKeys||!toKeys)return jsonRows;");	        
		writer.write("true","var resultArray=new Array(jsonRows.length);");	
		writer.write("true","for(var i=0;i<jsonRows.length;i++){");	
		writer.write("true","var rowJsonData = new Object();");	
		writer.write("true","for(var j=0;j<fromKeys.length;j++){");	
		writer.write("true","rowJsonData[toKeys[j]]=jsonRows[i][fromKeys[j]];");	
		writer.write("true","}");	
		writer.write("true","resultArray[i]=rowJsonData;");	
		writer.write("true","}");	
		writer.write("true","return resultArray;");	
		writer.write("true","};\r\n");		
				
		writer.html("true","", "tree(rowsData,levelName,isGroup)", "工具方法，用于将行存储的查询结果集按照LEVEL列名转换为一棵树", "系统", "",
				"rowsData：为行数组结果集;levelName:指定列名，用于标志树的层次的整数值;isGroup:是否分组，如果为true则复选框不起作用", "json树",
				"var treeData="+jsControlName+".tree(rowsData,\"LEVEL\",true);");
		writer.write("true","	this.tree=function(rowsData,levelName,isGroup,rowIndex){");	
		writer.write("true","if(!rowsData||!levelName)return null;");	
		writer.write("true","if(!rowIndex){");	
		writer.write("true","rowIndex=new Object();");	
		writer.write("true","rowIndex.value=0;");	
		writer.write("true","}");		
		writer.write("true","if(!isGroup||isGroup!=true)isGroup=false;");
		writer.write("true","var resultArray=new Array();");	
		writer.write("true","var level=-1;");	
		writer.write("true","while(rowIndex.value<rowsData.length){");	           
		writer.write("true","var l_level=rowsData[rowIndex.value][levelName];");	
		writer.write("true","if(level==-1)level=l_level;");	
		writer.write("true","if(level==l_level){");	               
		writer.write("true","resultArray.push(rowsData[rowIndex.value]);");	
		writer.write("true","rowIndex.value++;");	                
		writer.write("true","}else if(level<l_level){");	
		writer.write("true","if(isGroup)resultArray[resultArray.length-1][\"group\"]=true;");	
		writer.write("true","resultArray[resultArray.length-1][\"sub\"]=this.tree(rowsData,levelName,isGroup,rowIndex);");	                 
		writer.write("true","}else if(level>l_level){");	               
		writer.write("true","return resultArray;");	
		writer.write("true","}");	
		writer.write("true","}");	
		writer.write("true","return resultArray;");	
		writer.write("true","};\r\n");
		
		writer.html("false","", "table(rowsData,collumNameArray,collunTypeArray)", "工具方法，用于将查询的二维json数组转换成table控件可识别的格式", "系统", "",
				"rowsData：查询的二维JSON数组；collumNameArray:列名数组；collunTypeArray：表格控件类型数组", "TABLE控件的rows对象",
				"var rows=SFC.table(ACTIONS,[\"SELECT\",\"ID\",\"NAME\",\"COMMENT\"],[\"checkbox\",\"label\",\"label\",\"label\"]);");		
		writer.write("false","	this.table=function(rowsData,collumNameArray,collunTypeArray){");
		writer.write("false","var rows=new Array(rowsData.length);");
		writer.write("false","for(var i=0;i<rowsData.length;i++){");
		writer.write("false","var action=rowsData[i];");
		writer.write("false","var cells=new Array(collumNameArray.ength);");
		writer.write("false","for(var j=0;j<collumNameArray.length;j++){");
		writer.write("false","var cell=new Object();");
		writer.write("false","cell.value=action[collumNameArray[j]];");
		writer.write("false","if(collunTypeArray&&collunTypeArray[j]){");
		writer.write("false","cell.type=collunTypeArray[j];");
		writer.write("false","}else{");
		writer.write("false","cell.type=\"label\";");
		writer.write("false","}");
		writer.write("false","cells[j]=cell;");
		writer.write("false","}");
		writer.write("false","var row=new Object();");
		writer.write("false","row.cells=cells;");
		writer.write("false","rows[i]=row;");            
		writer.write("false","}");
		writer.write("false","return rows;");
		writer.write("false","};\r\n");
		
		writer.html("true","", "getDownloadUrl(fileName)", "工具方法，用于根据文件名生成文件下载地址", "系统", "",
				"fileName：文件名", "返回文件下载地址","var fileUrl="+jsControlName+".getDownloadUrl(fileName);");
		writer.write("true","	this.getDownloadUrl= function(fileName){");
		//writer.write("true","var timestamp = (new Date()).valueOf();");
		writer.write("true","var url = this.serverUrl + \"Download?UId=\"+encodeURIComponent(this.getUID());");
		writer.write("true","url=url+\"&File=\"+encodeURIComponent(encodeURIComponent(fileName));");
		writer.write("true","return url;");
		writer.write("true","};\r\n");
		
		StringBuffer sampleString=new StringBuffer();
		sampleString.append("	"+jsControlName+".getSystemActions(function(isOK,message,ACTIONS){   <br>\r\n");
		sampleString.append("	    &nbsp;&nbsp;if(isOK){//服务调用成功<br>\r\n");
		sampleString.append("	    &nbsp;&nbsp;}else{//服务调用失败，返回错误信息<br>\r\n");
		sampleString.append("	        &nbsp;&nbsp;&nbsp;&nbsp;var errorMessage=message;<br>\r\n");
		sampleString.append("	    &nbsp;&nbsp;}<br>\r\n");
		sampleString.append("	});\r\n");
		writer.html("true","", "getSystemActions(isPerformanceMonitor,callbackFunction)", "工具方法，用于列出系统允许全部后台接口说明,如果isPerformanceMonitor设置为1，则后台对每个服务开始进行耗时统计，0则关闭，其他数字保持不变", "系统", "",
				"isPerformanceMonitor：0/1;通过回调函数返回行数组", "json行数组:ACTIONS{ID,NAME,COMMENT,TOTAL_TIME,TOTAL_ACCESS}",
				sampleString.toString());
		writer.write("true","	this.getSystemActions=function(isPerformanceMonitor,callbackFunction){");
		writer.write("true","var timestamp = (new Date()).valueOf();");
		writer.write("true","var data ={IsPerformanceMonitor:isPerformanceMonitor};");
		writer.write("true","this.jsonPost(-1,false,data,function(jsonData,callback){callback(jsonData.IsOK, jsonData.Message,jsonData.ACTIONS);},callbackFunction);");		
		writer.write("true","};\r\n");
		writer.html("true","", "toDateStr(dateVar)", "工具方法，用于将Date对象传换成YYYY-MM-DD格式字符串", "系统", "",
				"js的Date对象", "yyyy-mm-dd格式日期字符串"," var YXRQ_Q="+jsControlName+".toDateStr(date); ");
		writer.write("true","	this.toDateStr=function(dateVar){");
		writer.write("true","if(!dateVar)return \"\";");
		writer.write("true","var nian=dateVar.getFullYear();");
		writer.write("true","var yue=dateVar.getMonth()+1;");
		writer.write("true","var ri=dateVar.getDate();");
		writer.write("true","if(yue.length==1)yue=\"0\"+yue;");
		writer.write("true","if(ri.length==1)ri=\"0\"+ri;");
		writer.write("true","return nian+\"-\"+yue+\"-\"+ri;");        
		writer.write("true","};\r\n");
		return writer;
	}

	public void analyzeToJsWeb(CodeGenerator codeGenerator,JsFileWriter writer,String jsControlName) throws Exception {		
		for (int i = 0; i < methodBuilders.size(); i++) {
			try {
				StringBuffer[] jsAndDoc=methodBuilders.get(i).getJsWebCode(jsControlName);
				String isApp=methodBuilders.get(i).getMethod().getIsMobilApp();
				writer.write(isApp,jsAndDoc[0].toString());
				writer.htmlWrite(jsAndDoc[1].toString());
				writer.flush();
			} catch (Exception e) {
				codeGenerator.addMessage("方法"
						+ methodBuilders.get(i).getMethod().getName()
						+ "解析出错，该方法将会跳过：" + e.getMessage() + "\r\n");
			}
		}
		//writer.write("}");
		writer.flush();
		//writer.close();
	}
	
	public void analyzeToJavaClient(CodeGenerator codeGenerator,JavaClientCode javaClient) throws Exception {
		for (int i = 0; i < methodBuilders.size(); i++) {
			try {
				javaClient.write(methodBuilders.get(i).getJavaClientCode().toString());				
			} catch (Exception e) {
				e.printStackTrace();
				codeGenerator.addMessage("方法"
						+ methodBuilders.get(i).getMethod().getName()
						+ "解析出错，该方法将会跳过：" + e.getMessage() + "\r\n");
			}
		}		
	}
	public void analyzeToIosClient(CodeGenerator codeGenerator,IosClientCode iosClient, String jsControlName) throws Exception {
		for (int i = 0; i < methodBuilders.size(); i++) {
			try {
				StringBuffer[] returnSb=methodBuilders.get(i).getIosClientCode(jsControlName);
				iosClient.head(returnSb[0].toString());		
				iosClient.write(returnSb[1].toString());				
			} catch (Exception e) {
				e.printStackTrace();
				codeGenerator.addMessage("方法"
						+ methodBuilders.get(i).getMethod().getName()
						+ "解析出错，该方法将会跳过：" + e.getMessage() + "\r\n");
			}
		}		
	}

	public void analyzeToJava(CodeGenerator codeGenerator) throws Exception {
		File file = new File(filePath);
		if (file.exists()) {
			file.delete();
		}
		OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
		//FileWriter writer = new FileWriter(file);
		writer.write(getClassHead().toString());
		writer.flush();
		for (int i = 0; i < methodBuilders.size(); i++) {
			try {
				writer.write(methodBuilders.get(i).getJavaCode().toString());
				writer.flush();
			} catch (Exception e) {
				e.printStackTrace();
				codeGenerator.addMessage("文件" + file + "中方法"
						+ methodBuilders.get(i).getMethod().getName()
						+ "解析出错，该方法将会跳过：" + e.getMessage() + "\r\n");
			}
		}
		writer.write("}");
		writer.flush();
		writer.close();
	}

	public List<Action> getActionDefinations() throws Exception {
		List<Action> actions = new ArrayList<Action>();
		for (int i = 0; i < methodBuilders.size(); i++) {
			actions.add(methodBuilders.get(i).getActionsDefination());
		}
		return actions;
	}
	private StringBuffer getClassHead() {
		StringBuffer code = new StringBuffer();
		code.append("package " + classPackagename + ";\r\n");
		code.append("\r\n");
		code.append("import java.util.*;\r\n");
		code.append("import org.json.JSONArray;\r\n");
		code.append("import org.json.JSONObject;\r\n");
		code.append("import com.yx.frame.jdbc.*;\r\n");
		code.append("import com.yx.frame.service.ServiceError;\r\n");
		code.append("import com.yx.frame.service.ServiceResult;\r\n");
		code.append("import com.yx.frame.util.Format;\r\n");
		code.append("import com.yx.frame.jdbc.Table;\r\n");
		code.append("import com.yx.frame.authority.User;\r\n");
		code.append("import com.yx.frame.service.Service;\r\n");
		code.append("\r\n");
		code.append("public final class " + className + "  extends Service {\r\n");
		//code.append("	Sql sql=null;\r\n");
		//code.append("	public " + className
		//		+ "(String dbName) throws Exception {\r\n");
		//code.append("		sql=new Sql(dbName);\r\n");
		//code.append("	}\r\n");
		code.append("	public " + className + "()  throws Exception {\r\n");
		//code.append("		this(null);\r\n");
		code.append("	}\r\n");
		Sql sql = null;
		return code;
	}

}
